package com.example.touchdemo.views;

import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

public class MultiTouchView extends androidx.appcompat.widget.AppCompatTextView{
    public static final String TAG="Multiview";
    private float x1,x2,y1,y2;
    public MultiTouchView( Context context) {
        super(context);
    }

    public MultiTouchView( Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

   public boolean onTouchEvent(MotionEvent event){
        int index=event.getActionIndex();
        switch (event.getActionMasked()){
            case MotionEvent.ACTION_DOWN:
                Log.d(TAG, "第一个手指按下==============================");
                break;
            case MotionEvent.ACTION_UP:
                Log.d(TAG, "最后一个手指抬起======================");
                break;
            case MotionEvent.ACTION_MOVE:
               if (event.getPointerCount()==2){
                   x2 =event.getX(1);
                   y2 =event.getY(1);

                   x1 =event.getX(0);
                   y1 =event.getY(0);
                   Log.d(TAG, "=======pointer======move"+"("+x1+","+y1+"),("+x2+","+y2+")");
               }
                break;
            case MotionEvent.ACTION_POINTER_DOWN:
                Log.e(TAG,"第"+(index+1)+"个手指按下");
                break;
            case MotionEvent.ACTION_POINTER_UP:
                Log.e(TAG,"第"+(index+1)+"个手指抬起");
                break;
        }
       return super.onTouchEvent(event);
   }
}
